# -*- encoding: utf-8 -*-

from Common.mysql import db
from Common.public_method import utc_8
from src.ApiTest.ApiCase.Database.api_case_database import ApiCase
from Common.yaml_method import YamlMethod


class AddApiCase:
    """
    新增接口测试用例接口
    """
    @staticmethod
    def add_api_case(data_name, project_id, project_name, request_info, create_user):
        """
        新增接口测试用例接口
        :param data_name: 接口名称
        :param project_id: 项目ID
        :param project_name: 项目名称
        :param request_info: 请求信息
        :param create_user: 创建人
        :return:
        """

        code = YamlMethod().read_data('code.yaml')['code']

        create_time = utc_8()
        status = 0
        # 插入数据库
        info = ApiCase(caseName=data_name, projectId=project_id, projectName=project_name, requestInfo=request_info,
                       status=status, create_time=create_time, create_user=create_user)
        db.session.add(info)
        db.session.commit()

        res = {
            'code': code[0],
            'message': 'success',
            'data': {}
        }
        return res
